﻿using System;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Collections;
using System.Web.UI;
using System.Transactions;


public partial class Main_ServiceInvoice_Receipt : System.Web.UI.Page
{
    Datautility DU = new Datautility();
    string strFinyear = "";
    string strsql = string.Empty;
    int counter = 1;
    int count_For_TDS = 0;
    int count_For_Rows = 0;

    List<string> listcounter;
    List<string> listddltype;
    List<string> listtxtparticulars;
    List<string> listddlparticulars; 
    List<string> listddlnature;
    List<string> listtxtorgamt;
    List<string> listtxtpendamt;
    List<string> listhidpendamt;
    List<string> listtxtamt;

    List<string> LstDetailsRowId;
    List<string> LstDetailsCount;
    List<string> LstDetailsParticular;
    List<string> LstDetailsService;
    List<string> LstDetailsBalanceAmt;
    List<string> LstDetailsTDSAmt;
    List<string> LstDetailsWriteOffAmt;
   
    protected override void LoadViewState(object savedState)
    {
        base.LoadViewState(savedState);
        OverrideADDMore();
        _Override_AddMore_WriteOffDetalis();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["FINYEAR"] != null)
        {
            strFinyear = Session["FINYEAR"].ToString();
        }
        else
        {
            Response.Redirect("~/SessionExpired.aspx");
        }
        MaintainScrollPositionOnPostBack = true;
        if (!IsPostBack)
        {
            listcounter = new List<string>();
            ViewState["listcounter"] = listcounter;

            listddltype = new List<string>();
            ViewState["listddltype"] = listddltype;

            listtxtparticulars = new List<string>();
            ViewState["listtxtparticulars"] = listtxtparticulars;

            listddlparticulars = new List<string>();
            ViewState["listddlparticulars"]=listddlparticulars;

            listddlnature = new List<string>();
            ViewState["listddlnature"]=listddlnature;

            listtxtorgamt = new List<string>();
            ViewState["listtxtorgamt"] = listtxtorgamt;

            listtxtpendamt = new List<string>();
            ViewState["listtxtpendamt"] = listtxtpendamt;

            listhidpendamt = new List<string>();
            ViewState["listhidpendamt"] = listhidpendamt;


            listtxtamt = new List<string>();
            ViewState["listtxtamt"] = listtxtamt;

            //***************** TDS/ Write off Details  *************

            LstDetailsRowId = new List<string>();
            ViewState["LstDetailsRowId"] = LstDetailsRowId;

            LstDetailsCount = new List<string>();
            ViewState["LstDetailsCount"] = LstDetailsCount;

            LstDetailsParticular = new List<string>();
            ViewState["LstDetailsParticular"] = LstDetailsParticular;

            LstDetailsService = new List<string>();
            ViewState["LstDetailsService"] = LstDetailsService;

            LstDetailsBalanceAmt = new List<string>();
            ViewState["LstDetailsBalanceAmt"] = LstDetailsBalanceAmt;

            LstDetailsTDSAmt = new List<string>();
            ViewState["LstDetailsTDSAmt"] = LstDetailsTDSAmt;

            LstDetailsWriteOffAmt = new List<string>();
            ViewState["LstDetailsWriteOffAmt"] = LstDetailsWriteOffAmt;

            ddlParticular1.Style.Add("display", "none");
            //ddlParticular2.Style.Add("display", "none");
           
            //BindParticulars(ddlParticular2);
            if (Request.QueryString.Count > 0 || Request.QueryString != null)
            {
                if (!String.IsNullOrEmpty(Request.QueryString["AmountType"]))
                {
                    if (Request.QueryString["AmountType"] != null || Request.QueryString["AmountType"].ToString() != string.Empty)
                    {

                        if (Request.QueryString["AmountType"].ToString() == "ACT")
                        {
                            rbtAmountType.Items[1].Selected = true;
                            rbtAmountType.Items[0].Selected = false;
                        }
                        else if (Request.QueryString["AmountType"].ToString() == "PROP")
                        {
                            rbtAmountType.Items[1].Selected = false;
                            rbtAmountType.Items[0].Selected = true;
                        }
                    }
                }
                else if (!String.IsNullOrEmpty(Request.QueryString["Result"]))
                {
                    if (Request.QueryString["Result"] != null || Request.QueryString["Result"].ToString() != string.Empty)
                    {
                        if (Request.QueryString["Result"].ToString() == "success")
                        {
                            lblMsg.Text = "Receipt Created Successfully...";
                        }
                    }
                }
            }
            
            BindFormat();
            BindCustomer();
            _BindService(ddlNature1);
            //BindService(ddlNature2);
            BindCashBankLedger(ddlCashType, "0"); // 0 for Cash
            BindCashBankLedger(ddlBankType, "1"); // 1 for Bank
            txtDate.Text = string.Format("{0:dd/MM/yyyy}", Convert.ToDateTime(System.DateTime.Now.ToString()));
        }
    }
    protected void BindFormat()
    {
        SqlParameter[] parma = { 
                                new SqlParameter("@transactiontype","2") /// 2 for Receipt
                               };
        DataTable dtFormat = DU.getdatausingprocedure("USP_IVC_GetAllTransactionFormatNameID", parma);
        if (dtFormat.Rows.Count > 0)
        {
            ddlFormat.DataSource = dtFormat;
            ddlFormat.DataTextField = "formatname";
            ddlFormat.DataValueField = "formatid";
            ddlFormat.DataBind();
            ddlFormat.Items.Insert(0, new ListItem("--- Select Format ---", "0"));            
        }
    }
    protected void ddlFormat_SelectedIndex(object sender, EventArgs e)
    {
        txtPrefix.Text = string.Empty;
        txtReceiptNo.Text = string.Empty;
        txtSuffix.Text = string.Empty;
        if (ddlFormat.SelectedValue != "0")
        {
            SqlParameter[] sparamChkTDS =
                                    {
                                        new SqlParameter("@FORMATID",ddlFormat.SelectedValue)
                                    };
            DataTable dtChkTDSLID = DU.getdatausingprocedure("USP_IVC_GetTransactionFormat_HeadOfAccounts",sparamChkTDS);
            int TDSLID =Convert.ToInt32(dtChkTDSLID.Rows[0]["TDS_LEDGERID"].ToString());
            int Writoff =Convert.ToInt32(dtChkTDSLID.Rows[0]["WRITEOFF_LEDGERID"].ToString());
            if (TDSLID <= 0 && Writoff <= 0)
            {
                hyperTranFormat.NavigateUrl="TransactionFormat/RecieptFormat.aspx?Status=Edit&action=Edit&FormatId="+ddlFormat.SelectedValue+"";
                modalFormatExtender.Show();
            }
            else
            {
                hidTDSLID.Value = TDSLID.ToString();
                hidWriteoffLID.Value = Writoff.ToString();
                string strFinyear = "";
                if (Session["FINYEAR"].ToString() != string.Empty)
                {
                    strFinyear = Session["FINYEAR"].ToString();
                }
                if (strFinyear != string.Empty)
                {
                    SqlParameter[] sparam =
                                    {
                                        new SqlParameter("@TFOID",ddlFormat.SelectedValue),
                                        new SqlParameter ("@FINYEAR",strFinyear)
                                    };
                    DataTable DTVoucher = DU.getdatausingprocedure("USP_IVC_GetMaxVoucherNo", sparam);
                    if (DTVoucher.Rows.Count > 0)
                    {
                        txtPrefix.Text = DTVoucher.Rows[0]["prefix"].ToString();
                        txtReceiptNo.Text = DTVoucher.Rows[0]["vouno"].ToString();
                        txtSuffix.Text = DTVoucher.Rows[0]["suffix"].ToString();
                    }
                }
                else
                {
                    Response.Redirect("~/SessionExpired.aspx");
                }
            }
        }
    }
    protected void BindCustomer()
    {
        DataTable dtCustomer = DU.getdatausingprocedure("USP_IVC_GetCustomerLedger");
        if (dtCustomer.Rows.Count > 0)
        {
            ddlCustomer.DataSource = dtCustomer;
            ddlCustomer.DataTextField = "LNAME";
            ddlCustomer.DataValueField = "LID";
            ddlCustomer.DataBind();
            ddlCustomer.Items.Insert(0,new ListItem("-- Select Customer --", "0"));
            
        }
    }
    private void  _BindService(DropDownList ddl)
    {
        DataTable DT = DU.getdatausingprocedure("USP_IVC_GetAllServices");
        if (DT.Rows.Count > 0)
        {
            ddl.DataSource = DT;
            ddl.DataTextField = "ServiceName";
            ddl.DataValueField = "ServiceId";
            ddl.DataBind();
            ddl.Items.Insert(0, new ListItem("-Select Service-", "0"));
        }
    }
    protected void ddlCustomer_SelectedIndexChanged(object sender, EventArgs e)
    {
        txtBalance.Text = string.Empty;
        
        if (ddlCustomer.SelectedValue != "0")
        {
            
            string strFinyear = Session["FINYEAR"].ToString();
            if (strFinyear != string.Empty)
            {
                SqlParameter[] parma = { 
                                new SqlParameter("@Lid",ddlCustomer.SelectedValue),
                                new SqlParameter("@Finyear",strFinyear)
                               };
                DataTable DtBalance = DU.getdatausingprocedure("USP_ACC_GetLedgerCurrentBalance", parma);
               
                if (DtBalance.Rows.Count > 0)
                {
                    txtBalance.Text = DtBalance.Rows[0]["ClosingBal"].ToString() + " " + DtBalance.Rows[0]["DebitCredit"].ToString();
                }
            }
            else
            {
                Response.Redirect("~/SessionExpired.aspx");
            } 
        }
        _GetParticular(ddlParticular1);
        //GridView1.DataSource = _ReturnPendingService_Details();
        //GridView1.DataBind();
        //GridView2.DataSource = _ReturnParticular();
        //GridView2.DataBind();
    }

    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        int rowno =Convert.ToInt32(GetLastNo(ddl.ID.ToString()));

        TextBox txtParticular = (TextBox)tblRecieptDetails.Rows[rowno].FindControl("txtParticular" + rowno);
        DropDownList ddlParticular = (DropDownList)tblRecieptDetails.Rows[rowno].FindControl("ddlParticular" + rowno);
        DropDownList ddlNature = (DropDownList)tblRecieptDetails.Rows[rowno].FindControl("ddlNature" + rowno);
        TextBox txtOriginalAmt = (TextBox)tblRecieptDetails.Rows[rowno].FindControl("txtOriginalAmt" + rowno);
        TextBox txtPendingAmt = (TextBox)tblRecieptDetails.Rows[rowno].FindControl("txtPendingAmt" + rowno);
        HiddenField hidPendingAmount = (HiddenField)tblRecieptDetails.Rows[rowno].FindControl("hidPendingAmount" + rowno);
        TextBox txtTotalAmt = (TextBox)tblRecieptDetails.Rows[rowno].FindControl("txtTotalAmt" + rowno);

        ddlNature.SelectedIndex = 0; 
        //ddlParticular.SelectedIndex = 0;
        txtParticular.Text = string.Empty;        
        txtPendingAmt.Text = string.Empty;
        txtOriginalAmt.Text = string.Empty;
        txtTotalAmt.Text = string.Empty;
        if (ddl.SelectedValue == "1" || ddl.SelectedValue == "0" || ddl.SelectedValue == "4")
        {
            ddlParticular.Style.Add("display", "none");
            txtParticular.Style.Add("display", "inline");
            txtParticular.CssClass = "input";
            hidPendingAmount.Value = "0";
            if (txtParticular.HasAttributes)
            {
                txtParticular.Attributes.Remove("onKeyDown");
            }
            ddlNature.Enabled = true;
            _DeleteCurrentRow_WriteOffDetails(rowno);
           
        }
        else if (ddl.SelectedValue == "2")
        {
            ddlParticular.Style.Add("display", "inline");
            txtParticular.Style.Add("display", "none");
            BindParticulars(ddlParticular);
            if (rbtAmountType.SelectedValue == "0")
            {
                ddlNature.Enabled = false;
            }
            else
            {
                ddlNature.Enabled = true;
            }
            _AddMore_WriteOffDetalis(rowno);
            //_BindAddMore_WriteOffDetails(rowno);
        }
        else if (ddl.SelectedValue == "3")
        {
            ddlParticular.Style.Add("display", "none");
            txtParticular.Style.Add("display", "inline");
            txtParticular.CssClass = "DisableInput";
            hidPendingAmount.Value = "0";
            txtParticular.Attributes.Add("onKeyDown", "return EnabledTabKey(this.id, event);");
            ddlNature.Enabled = true;
            _DeleteCurrentRow_WriteOffDetails(rowno);
        }       
    }
    
    protected void BindCashBankLedger(DropDownList ddl,string strAccountType)
    {
        SqlParameter[] parmacash = {
                                new SqlParameter("@ACCOUNTTYPE",strAccountType) // 0 for Cash Ledger
                               };
        
        DataTable dtCash = DU.getdatausingprocedure("USP_IVC_GetBankAndCashLedger", parmacash);
        if (dtCash.Rows.Count > 0)
        {
            ddl.DataSource = dtCash;
            ddl.DataTextField = "LNAME";
            ddl.DataValueField = "LID";
            ddl.DataBind();
            ddl.Items.Insert(0,new ListItem("-- Select Type --","0"));
        }
    }
    protected void BindParticulars(DropDownList ddl)
    {
        string strDate = string.Empty;
        if (txtDate.Text.ToString() != string.Empty)
        {
            string[] str = txtDate.Text.ToString().Split('/');
            strDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
        }

        if (ddlCustomer.SelectedValue != "0")
        {
            SqlParameter[] parma = { 
                                    new SqlParameter("@LID",ddlCustomer.SelectedValue),
                                    new SqlParameter("@VOUDATE",strDate),                                    
                                    new SqlParameter("@CURRENTTRANID","0"),
                                    new SqlParameter("@ISSALESRETURN","0"),
                                   };
            DataTable dtparticulars = DU.getdatausingprocedure("USP_IVC_GetPendingParticulars", parma);

            if (dtparticulars.Rows.Count > 0)
            {
                ddl.DataSource = dtparticulars;
                ddl.DataTextField = "Reference";
                ddl.DataValueField = "ReferenceID";
                ddl.DataBind();                
            }
        }
        ddl.Items.Insert(0, new ListItem("-- Select Particulars --", "0"));
    }
    private void _GetParticular(DropDownList ddl)
    {
        DataTable DTParticular = _ReturnParticular();
        ddl.DataSource = DTParticular;
        ddl.DataTextField = "Reference";
        ddl.DataValueField = "ReferenceId";
        ddl.DataBind();
        ddl.Items.Insert(0, new ListItem("", "0"));
    }
    protected void ddlParticulars_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        int rowIndex = Convert.ToInt32(GetLastNo(ddl.ID.ToString()));
        DataTable DTParticular = _ReturnParticular();
        DataTable DTService = _ReturnPendingService_Details();
     
        TextBox txtOriginalAmt = (TextBox)tblRecieptDetails.Rows[rowIndex].FindControl("txtOriginalAmt" + rowIndex);
        TextBox txtPendingAmt = (TextBox)tblRecieptDetails.Rows[rowIndex].FindControl("txtPendingAmt" + rowIndex);
        HiddenField hidPendingAmount = (HiddenField)tblRecieptDetails.Rows[rowIndex].FindControl("hidPendingAmount" + rowIndex);
        DropDownList ddlNature = (DropDownList)tblRecieptDetails.Rows[rowIndex].FindControl("ddlNature" + rowIndex);

        if (rbtAmountType.SelectedValue == "0")
        {
            ddlNature.Enabled = false;
            if (ddl.SelectedValue != "0")
            {
                DataView DVParticular = DTParticular.DefaultView;
                DVParticular.RowFilter = "ReferenceId='" + ddl.SelectedValue + "'";
                DataTable DTTempParticular = DVParticular.ToTable();

                string[] strOriginal = DTTempParticular.Rows[0]["OriginalAmount1"].ToString().Split(' ');
                txtOriginalAmt.Text = string.Format("{0:0.00}", Convert.ToDouble(strOriginal[0])) + " " + strOriginal[1];

                string[] strPending = DTTempParticular.Rows[0]["PendingAmount1"].ToString().Split(' ');
                txtPendingAmt.Text = string.Format("{0:0.00}", Convert.ToDouble(strPending[0])) + " " + strPending[1];
                hidPendingAmount.Value = string.Format("{0:0.00}", Convert.ToDouble(strPending[0]));
                _BindAddMore_WriteOffDetails(rowIndex);
            }
            else
            {
                txtOriginalAmt.Text = string.Empty;
                txtPendingAmt.Text = string.Empty;
                hidPendingAmount.Value = "0";
            }
        }
        else
        {
            ddlNature.Enabled = true;
            DataView DVService = DTService.DefaultView;
            DVService.RowFilter = "ReferenceSerial='" + ddl.SelectedValue + "'";
            ddlNature.DataTextField = "SERVICENAME";
            ddlNature.DataValueField = "SERVICEID";
            ddlNature.DataSource = DVService;
            ddlNature.DataBind();
            ddlNature.Items.Insert(0, new ListItem("-Select Service-", "0"));
        } 
    }
    protected void ddlNature_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList ddl = (DropDownList)sender;
        int rowIndex = Convert.ToInt32(GetLastNo(ddl.ID.ToString()));
        DataTable DTService = _ReturnPendingService_Details();

        DropDownList ddlParticular = (DropDownList)tblRecieptDetails.Rows[rowIndex].FindControl("ddlParticular" + rowIndex);
            TextBox txtOriginalAmt = (TextBox)tblRecieptDetails.Rows[rowIndex].FindControl("txtOriginalAmt" + rowIndex);
            TextBox txtPendingAmt = (TextBox)tblRecieptDetails.Rows[rowIndex].FindControl("txtPendingAmt" + rowIndex);
            HiddenField hidPendingAmount = (HiddenField)tblRecieptDetails.Rows[rowIndex].FindControl("hidPendingAmount" + rowIndex);

            if (rbtAmountType.SelectedValue == "1")
            {
                if (ddl.SelectedValue != "0")
                {
                    DataView DVService = DTService.DefaultView;
                    DVService.RowFilter = "SERVICEID='" + ddl.SelectedValue + "'";
                    DataTable DTTempService = DVService.ToTable();
                    if (DTTempService.Rows.Count > 0)
                    {
                        txtOriginalAmt.Text = string.Format("{0:0.00}", Convert.ToDouble(DTTempService.Rows[0]["Amount"].ToString()));
                        txtPendingAmt.Text = string.Format("{0:0.00}", Convert.ToDouble(DTTempService.Rows[0]["PendingAmount"].ToString()));
                        hidPendingAmount.Value = string.Format("{0:0.00}", Convert.ToDouble(DTTempService.Rows[0]["PendingAmount"].ToString()));
                        _BindAddMore_WriteOffDetails(rowIndex);
                    }
                }
                else
                {
                    txtOriginalAmt.Text = string.Empty;
                    txtPendingAmt.Text = string.Empty;
                    hidPendingAmount.Value = "0";
                }
            }
    }

    protected void ADDMore_Click(object sender, EventArgs e)
    {
        ADDMore();
    }

    protected void ADDMore()
    {
        counter++;
        listcounter.Add(counter.ToString());

        HtmlTableRow row1 = new HtmlTableRow();

        HtmlTableCell cell1 = new HtmlTableCell();
        cell1.Align = "center";
        DropDownList ddltype = new DropDownList();
        ddltype.ID = "ddltype" + counter.ToString();
        ddltype.CssClass = "dropdown";
        ddltype.Attributes.Add("onclick", "return CheckFormatCustomerRecvAmt();");
        ddltype.AutoPostBack = true;
        ddltype.Width = Unit.Percentage(98);
        insertTypeItem(ddltype);
        //ddltype.Attributes.Add("onchange", "return checkItemRepetion(this.id);");
        ddltype.SelectedIndexChanged += new EventHandler(ddlType_SelectedIndexChanged);


        listddltype.Add(ddltype.ID);

        HtmlTableCell cell2 = new HtmlTableCell();
        cell2.Align = "Center";
        TextBox txtParticular = new TextBox();
        txtParticular.ID = "txtParticular" + counter.ToString();
        txtParticular.Attributes.Add("onblur", "return CheckTypeParticular('txt',this.id); NoParticularRepeat(this.id,'txt');");
        txtParticular.CssClass = "input";
        txtParticular.Width = Unit.Percentage(98);

        listtxtparticulars.Add(txtParticular.ID);

        DropDownList ddlParticular = new DropDownList();
        ddlParticular.ID = "ddlParticular" + counter.ToString();
        ddlParticular.CssClass = "dropdown";
        _GetParticular(ddlParticular);
        ddlParticular.Style.Add("display", "none");
        ddlParticular.Attributes.Add("onchange", "return NoParticularRepeat(this.id,'ddl');");
        ddlParticular.Width = Unit.Percentage(98);
        ddlParticular.SelectedIndexChanged += new EventHandler(ddlParticulars_SelectedIndexChanged);

        listddlparticulars.Add(ddlParticular.ID);

        HtmlTableCell cell3 = new HtmlTableCell();
        cell3.Align = "center";
        DropDownList ddlNature = new DropDownList();
        ddlNature.ID = "ddlNature" + counter.ToString();
        ddlNature.CssClass = "dropdown";
        ddlNature.Attributes.Add("onchange" , "return CheckTypeParticular('ddlS',this.id);");
        ddlNature.Width = Unit.Percentage(98);
        ddlNature.AutoPostBack = true;
        ddlNature.SelectedIndexChanged +=new EventHandler(ddlNature_SelectedIndexChanged);
        _BindService(ddlNature);

        listddlnature.Add(ddlNature.ID);

        HtmlTableCell cell4 = new HtmlTableCell();
        cell4.Align = "Center";
        TextBox txtOriginalAmt = new TextBox();
        txtOriginalAmt.ID = "txtOriginalAmt" + counter.ToString();
        txtOriginalAmt.CssClass = "DisableInputNumber";
        txtOriginalAmt.Width = Unit.Percentage(98);
        txtOriginalAmt.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");

        listtxtorgamt.Add(txtOriginalAmt.ID);

        HtmlTableCell cell5 = new HtmlTableCell();
        cell5.Align = "Center";
        TextBox txtPendingAmt = new TextBox();
        txtPendingAmt.ID = "txtPendingAmt" + counter.ToString();
        txtPendingAmt.CssClass = "DisableInputNumber";
        txtPendingAmt.Width = Unit.Percentage(98);
        txtPendingAmt.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");

        HiddenField hidPendingAmount = new HiddenField();
        hidPendingAmount.ID = "hidPendingAmount" + counter.ToString();
        listtxtpendamt.Add(txtPendingAmt.ID);
        listhidpendamt.Add(hidPendingAmount.ID);

        HtmlTableCell cell6 = new HtmlTableCell();
        cell6.Align = "Center";
        TextBox txtTotalAmt = new TextBox();
        txtTotalAmt.ID = "txtTotalAmt" + counter.ToString();
        txtTotalAmt.Width = Unit.Percentage(98);
        txtTotalAmt.CssClass = "inputnumber";
        txtTotalAmt.Attributes.Add("OnKeyDown", "return CheckTypeParticularervice(this.id)");
        txtTotalAmt.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
        txtTotalAmt.Attributes.Add("onblur", "return ChkReceivedPendngTtlAmt('ttlAmt');");
        listtxtamt.Add(txtTotalAmt.ID);

        cell1.Controls.Add(ddltype);
        cell2.Controls.Add(txtParticular);
        cell2.Controls.Add(ddlParticular);
        cell3.Controls.Add(ddlNature);
        cell4.Controls.Add(txtOriginalAmt);
        cell5.Controls.Add(txtPendingAmt);
        cell5.Controls.Add(hidPendingAmount);
        cell6.Controls.Add(txtTotalAmt);

        row1.Cells.Add(cell1);
        row1.Cells.Add(cell2);
        row1.Cells.Add(cell3);
        row1.Cells.Add(cell4);
        row1.Cells.Add(cell5);
        row1.Cells.Add(cell6);

        tblRecieptDetails.Rows.Add(row1);

        hidRowCount.Value = counter.ToString();

        ViewState["listcounter"] = listcounter;
        ViewState["listddltype"] = listddltype;
        ViewState["listtxtparticulars"] = listtxtparticulars;
        ViewState["listddlparticulars"] = listddlparticulars;
        ViewState["listddlnature"] = listddlnature;
        ViewState["listtxtorgamt"] = listtxtorgamt;
        ViewState["listtxtpendamt"] = listtxtpendamt;
        ViewState["listhidpendamt"] = listhidpendamt;
        ViewState["listtxtamt"] = listtxtamt;
    }
    protected void OverrideADDMore()
    {
        listcounter = (List<string>)ViewState["listcounter"];
        listddltype = (List<string>)ViewState["listddltype"];
        listtxtparticulars = (List<string>)ViewState["listtxtparticulars"];
        listddlparticulars = (List<string>)ViewState["listddlparticulars"];
        listddlnature = (List<string>)ViewState["listddlnature"];
        listtxtorgamt = (List<string>)ViewState["listtxtorgamt"];
        listtxtpendamt = (List<string>)ViewState["listtxtpendamt"];
        listhidpendamt = (List<string>)ViewState["listhidpendamt"];
        listtxtamt = (List<string>)ViewState["listtxtamt"];

        if (listcounter != null)
        {
            int tempcounter = Convert.ToInt32(listcounter.Count);
            for (int i = 0; i < tempcounter; i++)
            {
                counter++;

                HtmlTableRow row1 = new HtmlTableRow();

                HtmlTableCell cell1 = new HtmlTableCell();
                cell1.Align = "center";
                DropDownList ddltype = new DropDownList();
                ddltype.ID = listddltype[i].ToString();
                ddltype.CssClass = "dropdown";
            //    ddltype.Attributes.Add("onchange", "return CheckFormatCustomerRecvAmt();");
                ddltype.Attributes.Add("onclick", "return CheckFormatCustomerRecvAmt();");
                ddltype.AutoPostBack = true;
                insertTypeItem(ddltype);
                ddltype.Width = Unit.Percentage(98);
                //ddltype.Attributes.Add("onchange", "return checkItemRepetion(this.id);");
                ddltype.SelectedIndexChanged += new EventHandler(ddlType_SelectedIndexChanged);

                HtmlTableCell cell2 = new HtmlTableCell();
                cell2.Align = "Center";
                TextBox txtParticular = new TextBox();
                txtParticular.ID = listtxtparticulars[i].ToString();
                txtParticular.CssClass = "input";
                txtParticular.Attributes.Add("onblur", "return CheckTypeParticular('txt',this.id); NoParticularRepeat(this.id,'txt');");
                txtParticular.Width = Unit.Percentage(98);

                DropDownList ddlParticular = new DropDownList();
                ddlParticular.ID = listddlparticulars[i].ToString();
                ddlParticular.CssClass = "dropdown";
                _GetParticular(ddlParticular);
                ddlParticular.Style.Add("display", "none");
                ddlParticular.Attributes.Add("onchange", "return NoParticularRepeat(this.id,'ddl');");
                ddlParticular.Width = Unit.Percentage(98);
                ddlParticular.SelectedIndexChanged += new EventHandler(ddlParticulars_SelectedIndexChanged);


                HtmlTableCell cell3 = new HtmlTableCell();
                cell3.Align = "center";
                DropDownList ddlNature = new DropDownList();
                ddlNature.ID = listddlnature[i].ToString();
                ddlNature.CssClass = "dropdown";
                ddlNature.Attributes.Add("onchange", "return CheckTypeParticular('ddlS',this.id);");
                ddlNature.Width = Unit.Percentage(98);
                ddlNature.AutoPostBack = true;
                ddlNature.SelectedIndexChanged += new EventHandler(ddlNature_SelectedIndexChanged);
                _BindService(ddlNature);

                HtmlTableCell cell4 = new HtmlTableCell();
                cell4.Align = "Center";
                TextBox txtOriginalAmt = new TextBox();
                txtOriginalAmt.ID = listtxtorgamt[i].ToString();
                txtOriginalAmt.CssClass = "DisableInputNumber";
                txtOriginalAmt.Width = Unit.Percentage(98);
                txtOriginalAmt.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");

                HtmlTableCell cell5 = new HtmlTableCell();
                cell5.Align = "Center";
                TextBox txtPendingAmt = new TextBox();
                txtPendingAmt.ID = listtxtpendamt[i].ToString();
                txtPendingAmt.CssClass = "DisableInputNumber";
                txtPendingAmt.Width = Unit.Percentage(98);
                txtPendingAmt.Attributes.Add("OnKeyDown", "return EnabledTabKey(this.ID,event);");
                HiddenField hidPendingAmount = new HiddenField();
                hidPendingAmount.ID = listhidpendamt[i].ToString();

                HtmlTableCell cell6 = new HtmlTableCell();
                cell6.Align = "Center";
                TextBox txtTotalAmt = new TextBox();
                txtTotalAmt.ID = listtxtamt[i].ToString();
                txtTotalAmt.Width = Unit.Percentage(98);
                txtTotalAmt.CssClass = "inputnumber";
                txtTotalAmt.Attributes.Add("OnKeyDown", "return CheckTypeParticularervice(this.id)");
                txtTotalAmt.Attributes.Add("OnKeyPress", "return isNumberKey(this.ID,event);");
                txtTotalAmt.Attributes.Add("onblur", "return ChkReceivedPendngTtlAmt('ttlAmt');");

                cell1.Controls.Add(ddltype);
                cell2.Controls.Add(txtParticular);
                cell2.Controls.Add(ddlParticular);
                cell3.Controls.Add(ddlNature);
                cell4.Controls.Add(txtOriginalAmt);
                cell5.Controls.Add(txtPendingAmt);
                cell5.Controls.Add(hidPendingAmount);
                cell6.Controls.Add(txtTotalAmt);

                row1.Cells.Add(cell1);
                row1.Cells.Add(cell2);
                row1.Cells.Add(cell3);
                row1.Cells.Add(cell4);
                row1.Cells.Add(cell5);
                row1.Cells.Add(cell6);

                tblRecieptDetails.Rows.Add(row1);
            }
        }
    }
    protected void insertTypeItem(DropDownList ddl)
    {
        ddl.Items.Insert(0, new ListItem("-- Select Type --", "0"));
        ddl.Items.Insert(1, new ListItem("New Bill", "1"));
        ddl.Items.Insert(2, new ListItem("Towards Bill", "2"));
        ddl.Items.Insert(3, new ListItem("On A/C", "3"));
        ddl.Items.Insert(4, new ListItem("Advance", "4"));
    }
    protected string GetLastNo(string strControlId)
    {
        string strno = string.Empty;
        string no = string.Empty;
        for (int i = 0; i < strControlId.Length; i++)
        {
            int num =0;
            no = strControlId.Substring(i, 1);
            if(int.TryParse(no,out num))
            {
                strno = strControlId.Substring(i);
                break;
            }
        }
        return strno;
    }
    private DataTable _ReturnParticular()
    {
        string strTranDate = string.Empty;
        DataTable DTParticular = new DataTable();
        if (txtDate.Text != string.Empty)
        {
            string[] str = txtDate.Text.Split('/');
            strTranDate = str[1] + "/" + str[0] + "/" + str[2];
        }
        if (ddlCustomer.SelectedValue != "0" && strTranDate != string.Empty)
        {
            SqlParameter[] sparam ={
                                   new SqlParameter("@LID",ddlCustomer.SelectedValue),
                                   new SqlParameter("@VOUDATE",strTranDate),
                                  // new SqlParameter("@FINYEAR",Session["FINYEAR"].ToString()),  /*Instructed by rajveer sir*/
                                   new SqlParameter("@CURRENTTRANID","0"),
                                   new SqlParameter("@ISSALESRETURN","0")
                               };
            DTParticular = DU.getdatausingprocedure("USP_IVC_GetPendingParticulars", sparam);
        }
        return DTParticular;
    }
    private DataTable _ReturnPendingService_Details()
    {
        string strTranDate = string.Empty;
        DataTable DTServiceDetails = new DataTable();
        if (txtDate.Text != string.Empty)
        {
            string[] str = txtDate.Text.Split('/');
            strTranDate = str[1] + "/" + str[0] + "/" + str[2];
        }
        if (ddlCustomer.SelectedValue != "0" && strTranDate != string.Empty)
        {
            SqlParameter[] sparam ={
                                   new SqlParameter("@CUSTOMERLEDGERID",ddlCustomer.SelectedValue),
                                   new SqlParameter("@VOUDATE",strTranDate),                                   
                                   new SqlParameter("@TRANID","0"),
                                   new SqlParameter("@ISSALESRETURN","0")
                               };
            DTServiceDetails = DU.getdatausingprocedure("USP_IVC_GetAllPendingServiceDetails", sparam);
        }
        return DTServiceDetails;
    }
    private void _AddMore_WriteOffDetalis(int intRowCounter)
    {
        HtmlTableRow HTRow = new HtmlTableRow();
        HTRow.ID = "WriteOffRow" + intRowCounter.ToString();
        LstDetailsRowId.Add(HTRow.ID.ToString());

        HtmlTableCell HTCell1 = new HtmlTableCell();        
        TextBox txtDetailsParticular = new TextBox();
        txtDetailsParticular.ID = "txtDetailsParticular" + intRowCounter.ToString();
        txtDetailsParticular.CssClass = "DisableInput";
        txtDetailsParticular.Width = Unit.Percentage(98);
        HTCell1.Controls.Add(txtDetailsParticular);
        LstDetailsCount.Add(intRowCounter.ToString());
        LstDetailsParticular.Add(txtDetailsParticular.ID);

        HtmlTableCell HTCell2 = new HtmlTableCell();
        TextBox txtDetailsService = new TextBox();
        txtDetailsService.ID = "txtDetailsService" + intRowCounter.ToString();
        txtDetailsService.CssClass = "DisableInput";
        txtDetailsService.Width = Unit.Percentage(98);
        HTCell2.Controls.Add(txtDetailsService);
        LstDetailsService.Add(txtDetailsService.ID);

        HtmlTableCell HTCell3 = new HtmlTableCell();
        TextBox txtDetailsBalanceAmt = new TextBox();
        txtDetailsBalanceAmt.ID = "txtDetailsBalanceAmt" + intRowCounter.ToString();
        txtDetailsBalanceAmt.CssClass = "DisableInputNumber";
        txtDetailsBalanceAmt.Width = Unit.Percentage(98);
        HTCell3.Controls.Add(txtDetailsBalanceAmt);
        LstDetailsBalanceAmt.Add(txtDetailsBalanceAmt.ID);


        HtmlTableCell HTCell4 = new HtmlTableCell();
        TextBox txtDetailsTDSAmt = new TextBox();
        txtDetailsTDSAmt.ID = "txtDetailsTDSAmt" + intRowCounter.ToString();
        txtDetailsTDSAmt.CssClass = "inputnumber";
        txtDetailsTDSAmt.Attributes.Add("OnKeyPress", "return isNumberKey(this.id,event);");
        txtDetailsTDSAmt.Attributes.Add("onblur", "return CheckWriteoffTDS('tds',this.id);");
        txtDetailsTDSAmt.Width = Unit.Percentage(98);
        HTCell4.Controls.Add(txtDetailsTDSAmt);
        LstDetailsTDSAmt.Add(txtDetailsTDSAmt.ID);

        HtmlTableCell HTCell5 = new HtmlTableCell();
        TextBox txtDetailsWriteOffAmt = new TextBox();
        txtDetailsWriteOffAmt.ID = "txtDetailsWriteOffAmt" + intRowCounter.ToString();
        txtDetailsWriteOffAmt.CssClass = "inputnumber";
        txtDetailsWriteOffAmt.Attributes.Add("OnKeyPress", "return isNumberKey(this.id,event);");
        txtDetailsWriteOffAmt.Attributes.Add("onblur", "return CheckWriteoffTDS('writeoff',this.id);");
        txtDetailsWriteOffAmt.Width = Unit.Percentage(98);
        HTCell5.Controls.Add(txtDetailsWriteOffAmt);
        LstDetailsWriteOffAmt.Add(txtDetailsWriteOffAmt.ID);

        HTRow.Cells.Add(HTCell1);
        HTRow.Cells.Add(HTCell2);
        HTRow.Cells.Add(HTCell3);
        HTRow.Cells.Add(HTCell4);
        HTRow.Cells.Add(HTCell5);        
        tblWriteOffDetails.Rows.Add(HTRow);
        hidWriteOffCount.Value = intRowCounter.ToString(); 
        
        ViewState["LstDetailsRowId"] = LstDetailsRowId;
        ViewState["LstDetailsCount"] = LstDetailsCount;
        ViewState["LstDetailsParticular"] = LstDetailsParticular;
        ViewState["LstDetailsService"] = LstDetailsService;
        ViewState["LstDetailsBalanceAmt"] = LstDetailsBalanceAmt;
        ViewState["LstDetailsTDSAmt"] = LstDetailsTDSAmt;
        ViewState["LstDetailsWriteOffAmt"] = LstDetailsWriteOffAmt;

    }
    private void _Override_AddMore_WriteOffDetalis()
    {        
        LstDetailsRowId = (List<string>)ViewState["LstDetailsRowId"];
        LstDetailsCount =(List<string>)ViewState["LstDetailsCount"];
        LstDetailsParticular = (List<string>)ViewState["LstDetailsParticular"];
        LstDetailsService = (List<string>)ViewState["LstDetailsService"];
        LstDetailsBalanceAmt = (List<string>)ViewState["LstDetailsBalanceAmt"];
        LstDetailsTDSAmt = (List<string>)ViewState["LstDetailsTDSAmt"];
        LstDetailsWriteOffAmt = (List<string>)ViewState["LstDetailsWriteOffAmt"];
        if (LstDetailsCount != null)
        {
            int intCount = Convert.ToInt32(LstDetailsCount.Count);
            for (int i = 0; i < intCount; i++)
            {
                HtmlTableRow HTRow = new HtmlTableRow();
                HTRow.ID = LstDetailsRowId[i].ToString();

                HtmlTableCell HTCell1 = new HtmlTableCell();
                TextBox txtDetailsParticular = new TextBox();
                txtDetailsParticular.ID = LstDetailsParticular[i].ToString();
                txtDetailsParticular.CssClass = "DisableInput";
                txtDetailsParticular.Width = Unit.Percentage(98);
                HTCell1.Controls.Add(txtDetailsParticular);               

                HtmlTableCell HTCell2 = new HtmlTableCell();
                TextBox txtDetailsService = new TextBox();
                txtDetailsService.ID = LstDetailsService[i].ToString();
                txtDetailsService.CssClass = "DisableInput";
                txtDetailsService.Width = Unit.Percentage(98);
                HTCell2.Controls.Add(txtDetailsService);               

                HtmlTableCell HTCell3 = new HtmlTableCell();
                TextBox txtDetailsBalanceAmt = new TextBox();
                txtDetailsBalanceAmt.ID = LstDetailsBalanceAmt[i].ToString();
                txtDetailsBalanceAmt.CssClass = "DisableInputNumber";
                txtDetailsBalanceAmt.Width = Unit.Percentage(98);
                HTCell3.Controls.Add(txtDetailsBalanceAmt);
                


                HtmlTableCell HTCell4 = new HtmlTableCell();
                TextBox txtDetailsTDSAmt = new TextBox();
                txtDetailsTDSAmt.ID = LstDetailsTDSAmt[i].ToString();
                txtDetailsTDSAmt.CssClass = "inputnumber";
                txtDetailsTDSAmt.Attributes.Add("OnKeyPress", "return isNumberKey(this.id,event);");
                txtDetailsTDSAmt.Attributes.Add("onblur", "return CheckWriteoffTDS('tds',this.id);");
                txtDetailsTDSAmt.Width = Unit.Percentage(98);
                HTCell4.Controls.Add(txtDetailsTDSAmt);
               

                HtmlTableCell HTCell5 = new HtmlTableCell();
                TextBox txtDetailsWriteOffAmt = new TextBox();
                txtDetailsWriteOffAmt.ID = LstDetailsWriteOffAmt[i].ToString();
                txtDetailsWriteOffAmt.CssClass = "inputnumber";
                txtDetailsWriteOffAmt.Attributes.Add("OnKeyPress", "return isNumberKey(this.id,event);");
                txtDetailsWriteOffAmt.Attributes.Add("onblur", "return CheckWriteoffTDS('writeoff',this.id);");
                txtDetailsWriteOffAmt.Width = Unit.Percentage(98);
                HTCell5.Controls.Add(txtDetailsWriteOffAmt);
               

                HTRow.Cells.Add(HTCell1);
                HTRow.Cells.Add(HTCell2);
                HTRow.Cells.Add(HTCell3);
                HTRow.Cells.Add(HTCell4);
                HTRow.Cells.Add(HTCell5);
                tblWriteOffDetails.Rows.Add(HTRow);
            }
        }
    }
    private void _DeleteCurrentRow_WriteOffDetails(int intLastNo)
    {
        if (intLastNo != 0)
        {           
            string strTempRowId = "WriteOffRow" + intLastNo.ToString();
            string strRowIndex = string.Empty;

            if (tblWriteOffDetails.Rows.Count > 1)
            {
                for (int i = 1; i < tblWriteOffDetails.Rows.Count; i++)
                {
                    if (tblWriteOffDetails.Rows[i].ID == strTempRowId)
                    {
                        strRowIndex = i.ToString();
                    }
                }            
                if (strRowIndex != string.Empty && Convert.ToInt32(strRowIndex) > 0)
                {
                    LstDetailsRowId = (List<string>)ViewState["LstDetailsRowId"];
                    LstDetailsCount = (List<string>)ViewState["LstDetailsCount"];
                    LstDetailsParticular = (List<string>)ViewState["LstDetailsParticular"];
                    LstDetailsService = (List<string>)ViewState["LstDetailsService"];
                    LstDetailsBalanceAmt = (List<string>)ViewState["LstDetailsBalanceAmt"];
                    LstDetailsTDSAmt = (List<string>)ViewState["LstDetailsTDSAmt"];
                    LstDetailsWriteOffAmt = (List<string>)ViewState["LstDetailsWriteOffAmt"];
                    if (LstDetailsParticular != null)
                    {
                        for (int i = 0; i < LstDetailsRowId.Count; i++)
                        {
                            if (LstDetailsRowId[i].ToString() == strTempRowId)
                            {                                
                                LstDetailsRowId.RemoveAt(i);
                                LstDetailsCount.RemoveAt(i);
                                LstDetailsParticular.RemoveAt(i);
                                LstDetailsService.RemoveAt(i);
                                LstDetailsBalanceAmt.RemoveAt(i);
                                LstDetailsTDSAmt.RemoveAt(i);
                                LstDetailsWriteOffAmt.RemoveAt(i);
                                i--;
                                tblWriteOffDetails.Rows.RemoveAt(Convert.ToInt32(strRowIndex));
                            }
                        }
                    }
                    ViewState["LstDetailsRowId"] = LstDetailsRowId;
                    ViewState["LstDetailsCount"] = LstDetailsCount;
                    ViewState["LstDetailsParticular"] = LstDetailsParticular;
                    ViewState["LstDetailsService"] = LstDetailsService;
                    ViewState["LstDetailsBalanceAmt"] = LstDetailsBalanceAmt;
                    ViewState["LstDetailsTDSAmt"] = LstDetailsTDSAmt;
                    ViewState["LstDetailsWriteOffAmt"] = LstDetailsWriteOffAmt;
                }
            }            
        }
    }
    private void _BindAddMore_WriteOffDetails(int intRowNo)
    {
        //txtTotalAmt1      txtDetailsService
        TextBox txtDetailsParticular = (TextBox)tblWriteOffDetails.FindControl("txtDetailsParticular" + intRowNo);
        TextBox txtDetailsService = (TextBox)tblWriteOffDetails.FindControl("txtDetailsService" + intRowNo);
        TextBox txtDetailsBalanceAmt = (TextBox)tblWriteOffDetails.FindControl("txtDetailsBalanceAmt" + intRowNo);
        DropDownList ddlParticular = (DropDownList)tblRecieptDetails.Rows[intRowNo].FindControl("ddlParticular" + intRowNo);
        DropDownList ddlNature = (DropDownList)tblRecieptDetails.Rows[intRowNo].FindControl("ddlNature" + intRowNo);
        HiddenField hidPendingAmount = (HiddenField)tblRecieptDetails.Rows[intRowNo].FindControl("hidPendingAmount" + intRowNo);
        TextBox txtTotalAmt = (TextBox)tblRecieptDetails.Rows[intRowNo].FindControl("txtTotalAmt" + intRowNo);
        txtDetailsParticular.Text = ddlParticular.SelectedItem.Text.ToString();
        if (rbtAmountType.SelectedValue == "1")
        {
          txtDetailsService.Text = ddlNature.SelectedItem.Text.ToString();
        }
        if (txtTotalAmt.Text != string.Empty)
        {
            txtDetailsBalanceAmt.Text =Convert.ToString(Convert.ToDouble(hidPendingAmount.Value) - Convert.ToDouble(txtTotalAmt.Text));
        }
        else
        {
            txtDetailsBalanceAmt.Text = "0";
        }
    }
    protected void rbtAmountType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rbtAmountType.Items[0].Selected)
        {
            Response.Redirect("Receipt.aspx?AmountType=PROP");
        }
        else if (rbtAmountType.Items[1].Selected)
        {
            Response.Redirect("Receipt.aspx?AmountType=ACT");
        }
    }
    protected string CheckParticular()
    {
        string result = "1,true,0";
        strsql = "select REFERENCE from ACC_REFDETAILS";
        DataTable dtCheckParticular = DU.getdata(strsql);
        int Count = Convert.ToInt32(hidRowCount.Value.ToString());
        for (int i = 1; i <= Count; i++)
        {
            DropDownList ddlType = (DropDownList)tblRecieptDetails.Rows[i].FindControl("ddlType" + i.ToString());
            if (ddlType.SelectedValue == "1" || ddlType.SelectedValue == "4")
            {
                DataView dvParticular = dtCheckParticular.DefaultView;
                TextBox txtParticular = (TextBox)tblRecieptDetails.Rows[i].FindControl("txtParticular" + i.ToString());
                string strExpr = "REFERENCE = '"+ txtParticular.Text.ToString()+"'";
                dvParticular.RowFilter = strExpr;
                DataTable dtFinal = dvParticular.ToTable();
                if (dtFinal.Rows.Count > 0)
                {
                    txtParticular.Focus();
                    result = "0,";
                    result += txtParticular.ID.ToString() + "," + i.ToString();
                    break;
                }
            }
        }
        return result;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            string [] result = CheckParticular().Split(',');
            string result1 = result[0].ToString();
            string result2 = result[1].ToString();
            string result3=result[2].ToString();
            if (result1 == "1")
            {
                string str = string.Empty;
                using (TransactionScope scope = new TransactionScope())
                {
                    str = _SaveVouchers();
                    scope.Complete();
                }
                if (str != string.Empty)
                {
                    Response.Redirect("Receipt.aspx?Result=success");
                }
            }
            else
            {
                lblMsg.Text = "Entered particular is already exist !!";
                //TextBox txt = (TextBox)tblRecieptDetails.Rows[Convert.ToInt32(result3)].FindControl(result2);
                TextBox txt = (TextBox)tblRecieptDetails.FindControl(result2);
                txt.Focus();
            }
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }
    }
    private string _SaveVouchers()
    {
        string strTranId = string.Empty;
        try
        {
            string strTranDate = string.Empty;
            string strTranTypeId = string.Empty;
            if (txtDate.Text != string.Empty)
            {
                string[] strTemp = txtDate.Text.Split('/');
                strTranDate = strTemp[1] + "/" + strTemp[0] + "/" + strTemp[2];
            }
            SqlParameter[] sparam ={
                                    new SqlParameter("@PARENTTYPEID","9"),
                                    new SqlParameter("@BILLFORMATID",ddlFormat.SelectedValue),
                                    new SqlParameter("@MODULETYPE","3")
                                };
            DataTable DTTranTypeId = DU.getdatausingprocedure("USP_ACC_GetTransactionSettingBasedOnFormat", sparam);
            if (DTTranTypeId.Rows.Count > 0)
            {
                strTranTypeId = DTTranTypeId.Rows[0]["TypeID"].ToString();
            }
            if (strTranTypeId != string.Empty)
            {
                SqlParameter[] sparam1 = 
                                {
                                    new SqlParameter("@TransactionTypeID",strTranTypeId),      
                                    new SqlParameter("@TransactionNumber",txtReceiptNo.Text),      
                                    new SqlParameter("@FinYear",Session["FINYEAR"].ToString()),      
                                    new SqlParameter("@ReferenceNumber",txtRefno.Text),     
                                    new SqlParameter("@IsCashVoucher","0"),      
                                    new SqlParameter("@TransactionDate",strTranDate),      
                                    new SqlParameter("@Narration",txtnarration.Text),     
                                    new SqlParameter("@CreditDays","0"),         
                                    new SqlParameter("@CreatedBy",Session["username"].ToString()),      
                                    new SqlParameter("@IsCancelled","0"),      
                                    new SqlParameter("@CostCentreClassID","0")  
                                };
                int Result = DU.executeprocedure("USP_ACC_SaveTransaction", sparam1);
                if (Result > 0)
                {
                   string strsql = "Select Ident_Current('ACC_VOUCHERS') as TranId";
                    DataTable DTTranId = DU.getdata(strsql);
                    if (DTTranId.Rows.Count > 0)
                    {
                        strTranId = DTTranId.Rows[0]["TranId"].ToString();
                        _SaveVouchers_Details(DTTranId.Rows[0]["TranId"].ToString());
                    }
                }
            }
        }
        catch (Exception ex)
        {
           //lblMsg.Text += ex.StackTrace;
            throw ex;
        }
        return strTranId;
    }
    private void _SaveVouchers_Details(string strTranId)
    {
        try
        {
            if (strTranId != string.Empty)
            {
                string strTranDate = string.Empty;
                if (txtDate.Text != string.Empty)
                {
                    string[] strTemp = txtDate.Text.Split('/');
                    strTranDate = strTemp[1] + "/" + strTemp[0] + "/" + strTemp[2];
                }
                    int count = Convert.ToInt32(hidRowCount.Value);
                    double totalAmount = 0;
                    double tdsAmount = 0;
                    double WriteOffAmount = 0;
                    
                    for (int i = 1; i <= count; i++)
                    {
                        TextBox txtTotalAmt = (TextBox)tblRecieptDetails.Rows[i].FindControl("txtTotalAmt" + i.ToString());
                        TextBox txtTDS = new TextBox();
                        txtTDS.Text = string.Empty;
                        TextBox txtWriteoff = new TextBox();
                        txtWriteoff.Text = string.Empty;
                        DropDownList ddlType = (DropDownList)tblRecieptDetails.Rows[i].FindControl("ddlType" + i.ToString());
                         if (ddlType.SelectedValue != "0" && ddlType.SelectedValue == "2")
                         {
                             if (Convert.ToInt32(hidWriteOffCount.Value) > 0 && tblWriteOffDetails.Rows.Count > 0 && Convert.ToInt32(hidWriteOffCount.Value)>= count)
                             {
                        
                                 txtTDS = (TextBox)tblWriteOffDetails.FindControl("txtDetailsTDSAmt" + i.ToString());
                                 if (txtTDS.Text == string.Empty)
                                 {
                                     txtTDS.Text = "0";
                                 }
                                 txtWriteoff = (TextBox)tblWriteOffDetails.FindControl("txtDetailsWriteOffAmt" + i.ToString());
                                 if (txtWriteoff.Text == string.Empty)
                                 {
                                     txtWriteoff.Text = "0";
                                 }
                             }
                         }
                        if (txtTotalAmt.Text != string.Empty && Convert.ToInt32(txtTotalAmt.Text.Trim()) > 0)
                        {
                            totalAmount += Convert.ToDouble(txtTotalAmt.Text.Trim());
                        }
                        if (txtTDS.Text != string.Empty && Convert.ToDouble(txtTDS.Text.Trim()) > 0)
                        {
                            tdsAmount += Convert.ToDouble(txtTDS.Text.Trim());
                        }
                        if (txtWriteoff.Text != string.Empty && Convert.ToDouble(txtWriteoff.Text) > 0)
                        {
                            WriteOffAmount += Convert.ToDouble(txtWriteoff.Text.Trim());
                        }
                    }
                    if (ddlCustomer.SelectedValue != "0")
                    {
                        if (totalAmount > 0)
                        {
                            string strReceiptId = _SaveReceipt_Main(strTranId);
                            Double netAmt = totalAmount + tdsAmount + WriteOffAmount;
                            SqlParameter[] sparam =
                                                {
                                                    new SqlParameter("@TransactionId",strTranId),
                                                    new SqlParameter("@LedgerId",ddlCustomer.SelectedValue),
                                                    new SqlParameter("@Amount",netAmt.ToString()),
                                                    new SqlParameter("@IsReconciled","0"),
                                                    new SqlParameter("@ReconciledDate",strTranDate)
                                                };
                            int Result = DU.executeprocedure("USP_ACC_SaveTransactionDetails", sparam);
                            if (Result > 0)
                            {
                                string strsql = "Select Ident_Current('ACC_VOUDETAILS') as VouSerial";
                                DataTable DT = DU.getdata(strsql);
                                if (DT.Rows.Count > 0)
                                {
                                    _SaveReference_Details(DT.Rows[0]["VouSerial"].ToString(), strReceiptId);
                                }
                            }
                        }
                    }
                    if (totalAmount > 0)
                    {
                        double amount = 0 - totalAmount;
                        SqlParameter[] sparam =
                                                {
                                                    new SqlParameter("@TransactionId",strTranId),
                                                    new SqlParameter("@LedgerId",ddlBankType.SelectedValue),
                                                    new SqlParameter("@Amount",amount.ToString()),
                                                    new SqlParameter("@IsReconciled","0"),
                                                    new SqlParameter("@ReconciledDate",strTranDate)
                                                };
                        DU.executeprocedure("USP_ACC_SaveTransactionDetails", sparam);
                    }
                    if (tdsAmount > 0)
                    {
                        double amount = 0 - tdsAmount;
                        SqlParameter[] sparam =
                                            {
                                                new SqlParameter("@TransactionId",strTranId),
                                                new SqlParameter("@LedgerId",hidTDSLID.Value),
                                                new SqlParameter("@Amount",amount.ToString()),
                                                new SqlParameter("@IsReconciled","0"),
                                                new SqlParameter("@ReconciledDate",strTranDate)
                                            };
                        DU.executeprocedure("USP_ACC_SaveTransactionDetails", sparam);
                    }
                    if (WriteOffAmount > 0)
                    {
                        double amount = 0 - WriteOffAmount;
                        SqlParameter[] sparam =
                                            {
                                                new SqlParameter("@TransactionId",strTranId),
                                                new SqlParameter("@LedgerId",hidWriteoffLID.Value),
                                                new SqlParameter("@Amount",amount.ToString()),
                                                new SqlParameter("@IsReconciled","0"),
                                                new SqlParameter("@ReconciledDate",strTranDate)
                                            };
                        DU.executeprocedure("USP_ACC_SaveTransactionDetails", sparam);
                    }
                }
        }
        catch (Exception ex)
        {
            //lblMsg.Text += ex.StackTrace;
            throw ex;
        }
    }
    private void _SaveReference_Details(string strVouSerial, string strReceiptId)
    {
        try
        {
            count_For_TDS = 0;
            count_For_Rows = 0;
            if (strVouSerial != string.Empty && strReceiptId != string.Empty)
            {
                string strRefDate = string.Empty;
                string strRefferenceNo = string.Empty;
                if (txtDate.Text.ToString() != string.Empty)
                {
                    string[] str = txtDate.Text.ToString().Split('/');
                    strRefDate = str[1].ToString() + "/" + str[0].ToString() + "/" + str[2].ToString();
                }
                int rowCount = Convert.ToInt32(hidRowCount.Value);
                for (int i = 1; i <= rowCount; i++)
                {
                    DropDownList ddlType = (DropDownList)tblRecieptDetails.Rows[i].FindControl("ddlType" + i);
                    DropDownList ddlParticular = new DropDownList();
                    TextBox txtParticular = new TextBox();
                    string particularValue = string.Empty;
                    string particularText=string.Empty;
                    if (ddlType.SelectedValue == "2")
                    {
                       ddlParticular = (DropDownList)tblRecieptDetails.Rows[i].FindControl("ddlParticular" + i);
                       particularText = ddlParticular.SelectedItem.Text.ToString();
                        particularValue=ddlParticular.SelectedValue.ToString();
                    }
                    else if (ddlType.SelectedValue != "2" && ddlType.SelectedValue != "0")
                    {
                        txtParticular = (TextBox)tblRecieptDetails.Rows[i].FindControl("txtParticular" + i);
                        particularText = txtParticular.Text;
                        particularValue = "0";
                    }
                    TextBox txtTotalAmt = (TextBox)tblRecieptDetails.Rows[i].FindControl("txtTotalAmt" + i);
                    if (txtTotalAmt.Text == string.Empty)
                    {
                        txtTotalAmt.Text = "0";
                    }
                    SqlParameter[] sparam = {
                                            new SqlParameter("@ReferenceSerial","0"),
                                            new SqlParameter("@ParentReference",particularValue),
                                            new SqlParameter("@TransactionSerial",strVouSerial),
                                            new SqlParameter("@ReferenceType",ddlType.SelectedValue),
                                            new SqlParameter("@Reference",particularText),
                                            new SqlParameter("@ReferenceDate",strRefDate),
                                            new SqlParameter("@CreditDays","0"),
                                            new SqlParameter("@ReferenceAmount",txtTotalAmt.Text.Trim()),
                                            new SqlParameter("@IsTDSDeducted","0")
                                };
                        int result = DU.executeprocedure("USP_ACC_SaveReferenceDetails", sparam);
                        if (result > 0)
                        {
                            strsql = "Select Ident_Current('ACC_REFDETAILS') as REFSERIAL";
                            DataTable DTRefdetails = DU.getdata(strsql);
                            if (DTRefdetails.Rows.Count > 0)
                            {
                                  _SaveReceipt_Child(strReceiptId, DTRefdetails.Rows[0]["REFSERIAL"].ToString(), i);
                            }
                        }
                }
                count_For_Rows = 0;
            }
        }
        catch (Exception ex)
        {
         //lblMsg.Text += ex.StackTrace;
            throw ex;
        }
    }
    private string _SaveReceipt_Main(string strTranId)
    {
        string strReceiptId = string.Empty;
        string strModeOfReceipt = string.Empty;
        string strModeDate=string.Empty;
        string strRemittingBank = string.Empty;
        if (txtmodedate.Text != string.Empty)
        {
            string[] strTemp = txtDate.Text.Split('/');
            strModeDate = strTemp[1] + "/" + strTemp[0] + "/" + strTemp[2];
        }
        if (rdldd.Checked == true)
        {
            strModeOfReceipt = "0";
            strRemittingBank = ddlBankType.SelectedValue.ToString();

        }
        else if (rdlcash.Checked == true)
        {
            strModeOfReceipt = "1";
            strRemittingBank = ddlCashType.SelectedValue.ToString();
        }
        else if (rdlcard.Checked == true)
        {
            strModeOfReceipt = "2";
             strRemittingBank = ddlBankType.SelectedValue.ToString();
        }
        try
        {
            RadioButtonList d = new RadioButtonList();
            SqlParameter [] sqlParamMain ={
                                        new SqlParameter("@RECEIPTID","0"),      
                                        new SqlParameter("@TRANID",strTranId),      
                                        new SqlParameter("@FORMATID",ddlFormat.SelectedValue),      
                                        new SqlParameter("@CUSTOMERLEDGERID",ddlCustomer.SelectedValue),      
                                        new SqlParameter("@TOTALAMT",txtRecievedAmt.Text),      
                                        new SqlParameter("@MODEOFRECEIPT",strModeOfReceipt),      
                                        new SqlParameter("@DDCHQNO",txtdd.Text),      
                                        new SqlParameter("@DDCHQBANK",txtBranch.Text),      
                                        new SqlParameter("@DDCHQDATE",strModeDate),      
                                        new SqlParameter("@CARDTYPE",txtcardtype.Text),      
                                        new SqlParameter("@ISSUEDBY",txtissuedby.Text),      
                                   //     new SqlParameter("@ACCTYPE",""),      
                                        new SqlParameter("@ACCNO","0"),      
                                        new SqlParameter("@REMITINGBANKID",strRemittingBank),      
                                        new SqlParameter("@CHECKEDBY",txtCheckedby.Text),      
                                        new SqlParameter("@PREPAREDBY",txtPreparedby.Text),      
                                        new SqlParameter("@SERVICEALLOCATIONTYPE",rbtAmountType.SelectedValue) 
                                      };
            int result = DU.executeprocedure("USP_IVC_SaveReceiptMain", sqlParamMain);
            if (result > 0)
            {
                string strsql = "Select Ident_Current('IVC_RECEIPT_MAIN') as RECEIPTID";
                DataTable DTCrediteNote = DU.getdata(strsql);
                if (DTCrediteNote.Rows.Count > 0)
                {
                    strReceiptId = DTCrediteNote.Rows[0]["RECEIPTID"].ToString();
                }
            }
        }
        catch (Exception ex)
        {
            lblMsg.Text += ex.StackTrace;
            throw ex;
        }
        return strReceiptId;
    }
    private void _SaveReceipt_Child(string strReceiptId, string strRefId, int rowIndex)
    {
        try
        {
            DataTable dtTempNature = new DataTable();
            DataTable dtTempParticular = new DataTable();
            string strTranDate = string.Empty;
            string strRefTranID = "0";
            string strRefChildID = "0";
            string strServiceID = "0";
            double TotalAmt = 0; Double domestic = 0; Double Export = 0; Double Examebted = 0;
            Double Others = 0; Double STRate = 0; Double HECess = 0; Double PECess = 0; Double STAmt = 0;
            Double HECessAmt = 0; Double PECessAmt = 0; Double TaxableAmt = 0; Double NonTaxableAmt = 0;
            int taxability =0;
            int subclass = 1;
            
            DropDownList ddlType = (DropDownList)tblRecieptDetails.Rows[rowIndex].FindControl("ddlType" + rowIndex);
            DropDownList ddlNature = (DropDownList)tblRecieptDetails.Rows[rowIndex].FindControl("ddlNature" + rowIndex);
            TextBox txtTotalAmt = (TextBox)tblRecieptDetails.Rows[rowIndex].FindControl("txtTotalAmt" + rowIndex);
            if (txtTotalAmt.Text != string.Empty && Convert.ToDouble(txtTotalAmt.Text) > 0)
            {
                TotalAmt = Convert.ToDouble(txtTotalAmt.Text);
            }
            if (ddlType.SelectedValue == "2")
            {
                DropDownList ddlParticular = (DropDownList)tblRecieptDetails.Rows[rowIndex].FindControl("ddlParticular" + rowIndex);
                DataTable dtParticular = _ReturnParticular();
                DataView dvParticular = dtParticular.DefaultView;
                string strParticlarExpr = "Referenceid = '" + ddlParticular.SelectedValue + "'";
                dvParticular.RowFilter = strParticlarExpr;
                dtTempParticular = dvParticular.ToTable();
               
                DataTable dtService = _ReturnPendingService_Details();
                DataView dvNature = dtService.DefaultView;
                string strNatureExpr = "ReferenceSerial= '" + ddlParticular.SelectedValue + "'";
                dvNature.RowFilter = strNatureExpr;
                dtTempNature = dvNature.ToTable();
                strsql = "select subclass,Taxability from IVC_SERVICEMASTER where serviceid=" + dtTempNature.Rows[rowIndex-1]["SERVICEID"].ToString() + "";
                DataTable dtServiceInfo = DU.getdata(strsql);
                if (dtServiceInfo.Rows[0]["taxability"].ToString() != string.Empty)
                {
                    taxability = Convert.ToInt32(dtServiceInfo.Rows[0]["taxability"].ToString());
                }
                if (dtServiceInfo.Rows[0]["subclass"].ToString() != string.Empty)
                {
                    subclass = Convert.ToInt32(dtServiceInfo.Rows[0]["subclass"].ToString());
                }
                if (dtTempParticular.Rows[count_For_Rows]["TransactionID"].ToString() != string.Empty)
                {
                    strRefTranID = dtTempParticular.Rows[count_For_Rows]["TransactionID"].ToString();
                }
                if (dtTempNature.Rows[count_For_Rows]["CHILDID"].ToString() != string.Empty)
                {
                    strRefChildID = dtTempNature.Rows[count_For_Rows]["CHILDID"].ToString();
                }
                if (dtTempNature.Rows[count_For_Rows]["SERVICEID"].ToString() != string.Empty)
                {
                    strServiceID = dtTempNature.Rows[count_For_Rows]["SERVICEID"].ToString();
                }
                count_For_Rows = count_For_Rows + 1;
            }
            else
            {
                //DataTable dtService = _ReturnPendingService_Details();
                //DataView dvNature = dtService.DefaultView;
                //string strNatureExpr = "SERVICEID=" + ddlNature.SelectedValue;
                //dtTempNature = dvNature.ToTable();
                strRefTranID = null;
                strRefChildID = null;
                strsql = "select subclass,Taxability from IVC_SERVICEMASTER where serviceid=" + ddlNature.SelectedValue.ToString() + "";
                DataTable dtServiceInfo = DU.getdata(strsql);
                if (dtServiceInfo.Rows[0]["taxability"].ToString() != string.Empty)
                {
                    taxability = Convert.ToInt32(dtServiceInfo.Rows[0]["taxability"].ToString());
                }
                if (dtServiceInfo.Rows[0]["subclass"].ToString() != string.Empty)
                {
                    subclass = Convert.ToInt32(dtServiceInfo.Rows[0]["subclass"].ToString());
                }
                strServiceID = ddlNature.SelectedValue.ToString();
            }
            if (txtDate.Text != string.Empty)
            {
                string[] strTemp = txtDate.Text.Split('/');
                strTranDate = strTemp[1] + "/" + strTemp[0] + "/" + strTemp[2];
            }
            if (subclass == 1)
            {
                SqlParameter [] sqlPara={
                                            new SqlParameter("@CURRENTDATE",strTranDate),
                                        };
                DataTable dtServiceTaxRate = DU.getdatausingprocedure("USP_IVC_GetCurrentServiceTaxRate", sqlPara);
                
                if (dtServiceTaxRate.Rows.Count > 0)
                {
                    if (dtServiceTaxRate.Rows[0]["SERVICETAX"].ToString() != string.Empty)
                    {
                        STRate = Convert.ToDouble(dtServiceTaxRate.Rows[0]["SERVICETAX"].ToString());
                    }
                    if (dtServiceTaxRate.Rows[0]["HCESS"].ToString() != string.Empty)
                    {
                        HECess = Convert.ToDouble(dtServiceTaxRate.Rows[0]["HCESS"].ToString());
                    }
                    if (dtServiceTaxRate.Rows[0]["PCESS"].ToString() != string.Empty)
                    {
                        PECess = Convert.ToDouble(dtServiceTaxRate.Rows[0]["PCESS"].ToString());
                    }
                   
                    domestic = (TotalAmt / (1 + ((STRate + HECess + PECess) / 100)));
                    STAmt = (domestic * STRate) / 100;
                    HECessAmt = (STAmt * HECess) / 100;
                    PECessAmt = (STAmt * PECess) / 100;
                    TaxableAmt = domestic;
                }

            }
            else if (subclass == 2)
            {
                Export = Convert.ToDouble(TotalAmt);
                TaxableAmt = Export;
                NonTaxableAmt = Export;
            }
            else if (subclass == 3)
            {
                Examebted = Convert.ToDouble(TotalAmt);
                TaxableAmt = Examebted;
                NonTaxableAmt = Examebted;
            }
            else if (subclass == 4)
            {
                Others = Convert.ToDouble(TotalAmt);
                TaxableAmt = Others;
                NonTaxableAmt = Others;
            }
            if (taxability == 0)
            {
                NonTaxableAmt = 0;
            }
            else
            {
                TaxableAmt = 0;
            }

            string strReceiptChildID = string.Empty;
            
            SqlParameter [] sqlParamChild = {
                                           new SqlParameter("@RECEIPTCHILDID","0"),      
                                           new SqlParameter("@RECEIPTID",strReceiptId),      
                                           new SqlParameter("@REFERENCETRANID",strRefTranID),      
                                           new SqlParameter("@REFERENCECHILDID",strRefChildID),      
                                           new SqlParameter("@REFERENCEID",strRefId),     
                                           new SqlParameter("@SERVICEID",strServiceID),      
                                           new SqlParameter("@RECEIPTAMOUNT",TotalAmt),      
                                           new SqlParameter("@DOMESTIC",domestic),      
                                           new SqlParameter("@EXEMPTED",Examebted),      
                                           new SqlParameter("@EXPORTED",Export),      
                                           new SqlParameter("@RECEIPTOTHER",Others),      
                                           new SqlParameter("@NONTAXAMT",NonTaxableAmt),      
                                           new SqlParameter("@CESS1RATE",PECess),      
                                           new SqlParameter("@CESS1AMT",PECessAmt),      
                                           new SqlParameter("@CESS2RATE",HECess),      
                                           new SqlParameter("@CESS2AMT",HECessAmt),      
                                           new SqlParameter("@SERVICERATE",STRate),      
                                           new SqlParameter("@SERVICEAMT",STAmt),      
                                           new SqlParameter("@TAXABLEAMT",TaxableAmt),      
                                           new SqlParameter("@ABATEMENTAMT","0"),      
                                           new SqlParameter("@SERVICECHARGEAMT","0"),      
                                           new SqlParameter("@REFERENCETYPE",ddlType.SelectedValue.ToString())    
                                         };
            int result = DU.executeprocedure("USP_IVC_SaveReceiptChild", sqlParamChild);
            if (result > 0)
            {
                strsql = "Select Ident_Current('IVC_RECEIPT_CHILD') as RECEIPTCHILDID";
                DataTable DTReceiptChild = DU.getdata(strsql);
                if (DTReceiptChild.Rows.Count > 0)
                {
                   strReceiptChildID = DTReceiptChild.Rows[0]["RECEIPTCHILDID"].ToString();
                  _SaveReceipt_TDS(strReceiptChildID, rowIndex, STRate,STAmt,PECess,PECessAmt,HECess,HECessAmt);
                }
            }
        }
        catch (Exception ex)
        {
            //lblMsg.Text += ex.StackTrace; 
            throw ex;
        }
    }
    private void _SaveReceipt_TDS(string strReceiptChildId, int rowIndex, Double STRate, Double STAmt, Double PECess, Double PECessAmt, Double HECess, Double HECessAmt)
    {
        try
        {
           // int coutntWriteOffTable=Convert.ToInt32(hidWriteOffCount.Value);
            DropDownList ddlType = (DropDownList)tblRecieptDetails.Rows[rowIndex].FindControl("ddlType" + rowIndex);

            TextBox txtTDS = new TextBox();
            txtTDS.Text = "0";
            TextBox txtWriteoff = new TextBox();
            txtWriteoff.Text = "0";
          
            if (ddlType.SelectedValue != "0" && ddlType.SelectedValue == "2")
            {
                if (Convert.ToInt32(hidWriteOffCount.Value) > 0 && tblWriteOffDetails.Rows.Count > 0  && Convert.ToInt32(hidWriteOffCount.Value)>= rowIndex)
                {
               
                    txtTDS = (TextBox)tblWriteOffDetails.FindControl("txtDetailsTDSAmt" + rowIndex);
                    //Response.Write("COunt for TDs"+count_For_TDS + "<br />");
                    if (txtTDS != null && txtTDS.Text == string.Empty)
                    {
                        txtTDS.Text = "0";
                    }
                    txtWriteoff = (TextBox)tblWriteOffDetails.FindControl("txtDetailsWriteOffAmt" + rowIndex);
                    if (txtWriteoff != null && txtWriteoff.Text == string.Empty)
                    {
                        txtWriteoff.Text = "0";
                    }
                }
            }
                 
            if (strReceiptChildId != string.Empty)
            {
                SqlParameter [] sqlParamTDS = {
                                               new SqlParameter("@RECEIPTCHILDID",strReceiptChildId),      
                                               new SqlParameter("@CESS1RATE",PECess),
                                               new SqlParameter("@CESS1AMT",PECessAmt),
                                               new SqlParameter("@CESS2RATE",HECess),
                                               new SqlParameter("@CESS2AMT",HECessAmt),      
                                               new SqlParameter("@SERVICERATE",STRate),
                                               new SqlParameter("@SERVICEAMT",STAmt),
                                               new SqlParameter("@TDS",Convert.ToDouble(txtTDS.Text)),
                                               new SqlParameter("@TDSTAXABLEAMT",Convert.ToDouble(txtTDS.Text)),
                                               new SqlParameter("@ABATEMENTAMT","0"),
                                               new SqlParameter("@SERVICECHARGEAMT","0"),
                                               new SqlParameter("@WRITEOFF",Convert.ToDouble(txtWriteoff.Text))
                                           };
                DU.executeprocedure("USP_IVC_SaveReceiptTDS", sqlParamTDS);
            }
        }
        catch (Exception ex)
        {
            //lblMsg.Text += ex.StackTrace;
            throw ex;
        }
    }

}
